﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Optimus
{
    class Kbd
    {
        
        public static uint Textx;
        public static uint Texty;
        public static uint Color = 8;
        public static void Loop()
        {
            int v = 0;
            while (true)
            {
                v++;
                Console.CursorLeft = 18;
                Console.CursorTop = 0;
                Console.Write("V: " + v.ToString());
            }
        }
        public static void WriteText(String Text)
        {
            foreach (char a in Text)
            {
                if (a == 'A')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.CapA, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'a')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.SmlA, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'B')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.CapB, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'b')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.SmlB, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'C')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.CapC, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'c')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.SmlC, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'D')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.CapD, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'd')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.SmlD, Color);
                    Textx = Textx + 6;
                }

                else if (a == 'E')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.CapE, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'e')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.SmlE, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'F')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.CapF, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'f')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.SmlF, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'G')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.CapG, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'g')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.SmlG, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'H')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.CapH, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'h')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.SmlH, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'I')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.CapI, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'i')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.SmlI, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'J')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.CapJ, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'j')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.SmlJ, Color);
                    Textx = Textx + 6;
                }

                else if (a == 'K')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.CapK, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'k')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.SmlK, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'L')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.CapL, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'l')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.SmlL, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'M')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.CapM, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'm')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.SmlM, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'N')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.CapN, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'n')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.SmlN, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'O')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.CapO, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'o')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.SmlO, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'P')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.CapP, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'p')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.SmlP, Color);
                    Textx = Textx + 6;
                }

                else if (a == 'Q')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.CapQ, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'q')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.SmlQ, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'R')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.CapR, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'r')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.SmlR, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'S')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.CapS, Color);
                    Textx = Textx + 6;
                }
                else if (a == 's')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.SmlS, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'T')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.CapT, Color);
                    Textx = Textx + 6;
                }
                else if (a == 't')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.SmlT, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'U')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.CapU, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'u')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.SmlU, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'V')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.CapV, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'v')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.SmlV, Color);
                    Textx = Textx + 6;
                }

                else if (a == 'W')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.CapW, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'w')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.SmlW, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'X')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.CapX, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'x')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.SmlX, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'Y')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.CapY, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'y')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.SmlY, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'Z')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.CapZ, Color);
                    Textx = Textx + 6;
                }
                else if (a == 'z')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.SmlZ, Color);
                    Textx = Textx + 6;
                }
                else if (a == ' ')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.Null, Color);
                    Textx = Textx + 6;
                }
                else if (a == '0')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.Zero, Color);
                    Textx = Textx + 6;
                }
                else if (a == '1')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.One, Color);
                    Textx = Textx + 6;
                }
                else if (a == '2')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.Two, Color);
                    Textx = Textx + 6;
                }
                else if (a == '3')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.Three, Color);
                    Textx = Textx + 6;
                }
                else if (a == '4')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.Four, Color);
                    Textx = Textx + 6;
                }
                else if (a == '5')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.Five, Color);
                    Textx = Textx + 6;
                }
                else if (a == '6')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.Six, Color);
                    Textx = Textx + 6;
                }
                else if (a == '7')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.Seven, Color);
                    Textx = Textx + 6;
                }
                else if (a == '8')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.Eight, Color);
                    Textx = Textx + 6;
                }
                else if (a == '9')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.Nine, Color);
                    Textx = Textx + 6;
                }
                else if (a == ':')
                {
                    NovaDraw2D.DrawTextChar(Textx, Texty, Font8x8.Colon, Color);
                    Textx = Textx + 6;
                }
            
            }
        }

        static ConsoleKey aKey = ConsoleKey.NoName;
        public static string TextBuffer = "";
        public static Cosmos.Hardware.Keyboard aKeyboard = new Cosmos.Hardware.Keyboard();
        static uint g = 0;

        public static void Execute()
        {
            while (true)
            {
                aKeyboard.GetScancode(out g);
                aKeyboard.GetKeyValue(g, out aKey);

                if (aKey == ConsoleKey.A)
                {
                    TextBuffer = TextBuffer + "a";
                }
                else if (aKey == ConsoleKey.B)
                {
                    TextBuffer = TextBuffer + "b";
                }
                else if (aKey == ConsoleKey.C)
                {
                    TextBuffer = TextBuffer + "c";
                }
                else if (aKey == ConsoleKey.D)
                {
                    TextBuffer = TextBuffer + "d";
                }
                else if (aKey == ConsoleKey.E)
                {
                    TextBuffer = TextBuffer + "e";
                }
                else if (aKey == ConsoleKey.F)
                {
                    TextBuffer = TextBuffer + "f";
                }
                else if (aKey == ConsoleKey.G)
                {
                    TextBuffer = TextBuffer + "g";
                }
                else if (aKey == ConsoleKey.H)
                {
                    TextBuffer = TextBuffer + "h";
                }
                else if (aKey == ConsoleKey.I)
                {
                    TextBuffer = TextBuffer + "i";
                }
                else if (aKey == ConsoleKey.J)
                {
                    TextBuffer = TextBuffer + "j";
                }
                else if (aKey == ConsoleKey.K)
                {
                    TextBuffer = TextBuffer + "k";
                }
                else if (aKey == ConsoleKey.L)
                {
                    TextBuffer = TextBuffer + "l";
                }
                else if (aKey == ConsoleKey.M)
                {
                    TextBuffer = TextBuffer + "m";
                }
                else if (aKey == ConsoleKey.N)
                {
                    TextBuffer = TextBuffer + "n";
                }
                else if (aKey == ConsoleKey.O)
                {
                    TextBuffer = TextBuffer + "o";
                }
                else if (aKey == ConsoleKey.P)
                {
                    TextBuffer = TextBuffer + "p";
                }
                else if (aKey == ConsoleKey.Q)
                {
                    TextBuffer = TextBuffer + "q";
                }
                else if (aKey == ConsoleKey.R)
                {
                    TextBuffer = TextBuffer + "r";
                }
                else if (aKey == ConsoleKey.S)
                {
                    TextBuffer = TextBuffer + "s";
                }
                else if (aKey == ConsoleKey.T)
                {
                    TextBuffer = TextBuffer + "t";
                }
                else if (aKey == ConsoleKey.U)
                {
                    TextBuffer = TextBuffer + "u";
                }
                else if (aKey == ConsoleKey.V)
                {
                    TextBuffer = TextBuffer + "v";
                }
                else if (aKey == ConsoleKey.W)
                {
                    TextBuffer = TextBuffer + "w";
                }
                else if (aKey == ConsoleKey.X)
                {
                    TextBuffer = TextBuffer + "x";
                }
                else if (aKey == ConsoleKey.Y)
                {
                    TextBuffer = TextBuffer + "y";
                }
                else if (aKey == ConsoleKey.Z)
                {
                    TextBuffer = TextBuffer + "z";
                }
                else if (aKey == ConsoleKey.Enter)
                {
                    Kernel.xResult = TextBuffer;
                   // Kernel.EnterPressed = true;
                    TextBuffer = "";
                }
            }

        }
    }
}



